package anthology.daily_question._24_11;
//https://leetcode.cn/problems/alternating-groups-ii/description/?envType=daily-question&envId=2024-11-27
public class _3208交替组2 {
    class Solution {
        public int numberOfAlternatingGroups(int[] colors, int k) {
            int n = colors.length;
            int ans = 0;
            int cnt = 0;
            for (int i = 0; i < n * 2; i++) {
                if (i > 0 && colors[i % n] == colors[(i - 1) % n]) {
                    cnt = 0;
                }
                cnt++;
                if (i >= n && cnt >= k) {
                    ans++;
                }
            }
            return ans;
        }
    }
}
